<?php
/**
 * klasa zarzadzajaca polaczeniem z baza danych 
 */

include_once('../general/infoWindow.class.php'); 
 
class Connection {
// pola ktore domyslnie powinny byc brane z pliku konfiguracyjnego

	//test purposes
	private $id;
	
	private $db_host = "localhost";
	private $db_name = "cfever_main";
	private $db_user = "cfever_admin";
	private $db_pass = "KarKor78";
	
	private $database;
	private $db_connection;
	
	public function Connection() {
		$this->id = rand();
	}
	
	function database($host = "localhost", $name = "cfever_main", $user = "cfever_admin", $pass = "KarKor78") {
	    $this->db_host = $host;
	    $this->db_name = $name;
	    $this->db_user = $user;
	    $this->db_pass = $pass;
	}
	
	function connect () {
//		$this->database = mysql_connect($this->db_host, $this->db_user, $this->db_pass) or
//		die( "Connecting failed!" );
//		
//		mysql_select_db($this->db_name) or
//		die(infoWindow::show("Błąd","Baza: ".$this->db_name." nie istnieje lub nie mozna sie z nia polaczyc!<br>"));

		$this->db_connection = new mysqli($this->db_host, $this->db_user, $this->db_pass, $this->db_name);
	}
	
	public function getPreparedStatement($query) {
		if(empty($query)) {
			print 'Connection: $query empty';
		}
		if(empty($this->db_connection)) {
			print 'Connection: $db_connection empty!';
		}
		return $this->db_connection->prepare($query);
	}
	
	public function executePreparedStatement($statement) {
		if(empty($statement)) {
			print 'Connection: $statement empty </br>';
		}
		return $statement->execute();
	}
	
	public function disconnect () {
		print $this->database;
		mysql_close($this->database);	
	}
	
	public function getId() {
		return $this->id;
	}
	

}
?>
